package com.yr.ryjk.backdoor.service;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yr.ryjk.backdoor.dao.BackdoorMapper;
import com.yr.ryjk.backdoor.entity.Backdoor;
import com.yr.ryjk.util.IDGenerator;

@Service
public class BackdoorService implements IBackdoorService {
	@Autowired
	private BackdoorMapper backdoorMapper;
	
	@Override
	public Backdoor getBackdoor() {
		return backdoorMapper.selectBackdoor();
	}

	@Override
	public void modify(Backdoor backdoor) {
		backdoor.setAddTime(new Date());
		backdoorMapper.updateByPrimaryKeySelective(backdoor);
	}

	@Override
	public Backdoor selectByPrimaryKey(String id) {
		return backdoorMapper.selectByPrimaryKey(id);
	}

	@Override
	public void add(Backdoor backdoor) {
		backdoorMapper.deleteByPrimaryKey(backdoor.getId());
		
		backdoor.setId(IDGenerator.gen32UUID());
		backdoor.setAddTime(new Date());
		
		backdoorMapper.insert(backdoor);
		
	}

	@Override
	public void delete(String id) {
		backdoorMapper.deleteByPrimaryKey(id);
	}
}